package com.yuqiang.user.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yuqiang.user.dao.UserInfoDao;
import com.yuqiang.user.model.bo.UserInfoBo;
import com.yuqiang.user.model.po.UserInfoPo;
import com.yuqiang.user.model.vo.UserInfoVo;
import com.yuqiang.user.service.UserInfoService;

@Service("userInfoService")
public class UserInfoServiceImpl implements UserInfoService {

	@Autowired
	private UserInfoDao userInfoDao;
	
	@Override
	public int selectUserInfoTotal(UserInfoBo userInfoBo) {
		//查询用户总条数    
		return userInfoDao.selectUserInfoTotal(userInfoBo);
	}

	@Override
	public List<UserInfoVo> selectUserInfoRows(UserInfoBo userInfoBo) {
		//分页查询用户    
		return userInfoDao.selectUserInfoRows(userInfoBo);
	}

	@Override
	public void updateUserInfoById(UserInfoBo userInfoBo) {
		//更新用户信息
		userInfoDao.updateUserInfoById(transform(userInfoBo));
	}

	@Override
	public int checkPassword(UserInfoBo userInfoBo) {
		//修改密码时判断初始密码
		return userInfoDao.checkPassword(userInfoBo);
	}
	
	private UserInfoPo transform(UserInfoBo userInfoBo){
		UserInfoPo userInfoPo = new UserInfoPo();
		//对象转换
		userInfoPo.setUserAddtime(userInfoBo.getUserAddtime());
		userInfoPo.setUserAge(userInfoBo.getUserAge());
		userInfoPo.setUserBirthday(userInfoBo.getUserBirthday());
		userInfoPo.setUserEmail(userInfoBo.getUserEmail());
		userInfoPo.setUserExp(userInfoBo.getUserExp());
		userInfoPo.setUserHouse(userInfoBo.getUserHouse());
		userInfoPo.setUserId(userInfoBo.getUserId());
		userInfoPo.setUserIsvalid(userInfoBo.getUserIsvalid());
		userInfoPo.setUserLastmodifiedby(userInfoBo.getUserLastmodifiedby());
		userInfoPo.setUserLastmodifiedtime(userInfoBo.getUserLastmodifiedtime());
		userInfoPo.setUserLevel(userInfoBo.getUserLevel());
		userInfoPo.setUserName(userInfoBo.getUserName());
		userInfoPo.setUserPassword(userInfoBo.getUserPassword());
		userInfoPo.setUserPhone(userInfoBo.getUserPhone());
		userInfoPo.setUserPicture(userInfoBo.getUserPicture());
		userInfoPo.setUserRealname(userInfoBo.getUserRealname());
		userInfoPo.setUserSex(userInfoBo.getUserSex());
		userInfoPo.setUserType(userInfoBo.getUserType());
		userInfoPo.setUserWork(userInfoBo.getUserWork());
		
		return userInfoPo;
	}
	
}
